package com.happy.cat.project.system.controller;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;

import java.util.List;
import java.util.Arrays;

import com.happy.cat.common.utils.StringUtils;
import lombok.AllArgsConstructor;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.happy.cat.framework.aspectj.lang.annotation.Log;
import com.happy.cat.framework.aspectj.lang.enums.BusinessType;
import com.happy.cat.project.system.domain.UserManitoLevelApply;
import com.happy.cat.project.system.service.IUserManitoLevelApplyService;
import com.happy.cat.framework.web.controller.BaseController;
import com.happy.cat.framework.web.domain.AjaxResult;
import com.happy.cat.common.utils.poi.ExcelUtil;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;

import com.happy.cat.framework.web.page.TableDataInfo;

/**
 * 大神等级申请Controller
 *
 * @author verne
 * @date 2020-08-19
 */
@AllArgsConstructor
@RestController
@RequestMapping("/system/userManitoLevelApply" )
@Api("大神等级申请 API")
public class UserManitoLevelApplyController extends BaseController {

    private final IUserManitoLevelApplyService iUserManitoLevelApplyService;

    /**
     * 查询大神等级申请列表
     */
    @ApiOperation(value = "查询大神等级申请列表",notes = "查询大神等级申请列表",response = TableDataInfo.class)
    @PreAuthorize("@ss.hasPermi('system:userManitoLevelApply:list')")
    @GetMapping("/list")
    public TableDataInfo list(UserManitoLevelApply userManitoLevelApply)
    {
        startPage();
        LambdaQueryWrapper<UserManitoLevelApply> lqw = new LambdaQueryWrapper<UserManitoLevelApply>();
        if (userManitoLevelApply.getAccountId() != null){
            lqw.eq(UserManitoLevelApply::getAccountId ,userManitoLevelApply.getAccountId());
        }
        if (userManitoLevelApply.getManitoId() != null){
            lqw.eq(UserManitoLevelApply::getManitoId ,userManitoLevelApply.getManitoId());
        }
        if (StringUtils.isNotBlank(userManitoLevelApply.getApplyLevel())){
            lqw.eq(UserManitoLevelApply::getApplyLevel ,userManitoLevelApply.getApplyLevel());
        }
        if (StringUtils.isNotBlank(userManitoLevelApply.getApplyText())){
            lqw.eq(UserManitoLevelApply::getApplyText ,userManitoLevelApply.getApplyText());
        }
        if (userManitoLevelApply.getApplyStatus() != null){
            lqw.eq(UserManitoLevelApply::getApplyStatus ,userManitoLevelApply.getApplyStatus());
        }
        if (userManitoLevelApply.getApplyTime() != null){
            lqw.eq(UserManitoLevelApply::getApplyTime ,userManitoLevelApply.getApplyTime());
        }
        if (StringUtils.isNotBlank(userManitoLevelApply.getApplyBy())){
            lqw.eq(UserManitoLevelApply::getApplyBy ,userManitoLevelApply.getApplyBy());
        }
        List<UserManitoLevelApply> list = iUserManitoLevelApplyService.list(lqw);
        return getDataTable(list);
    }

    /**
     * 导出大神等级申请列表
     */
    @ApiOperation(value = "导出大神等级申请列表",notes = "导出大神等级申请列表",response = AjaxResult.class)
    @PreAuthorize("@ss.hasPermi('system:userManitoLevelApply:export')" )
    @Log(title = "大神等级申请" , businessType = BusinessType.EXPORT)
    @GetMapping("/export" )
    public AjaxResult export(UserManitoLevelApply userManitoLevelApply) {
        LambdaQueryWrapper<UserManitoLevelApply> lqw = new LambdaQueryWrapper<UserManitoLevelApply>(userManitoLevelApply);
        List<UserManitoLevelApply> list = iUserManitoLevelApplyService.list(lqw);
        ExcelUtil<UserManitoLevelApply> util = new ExcelUtil<UserManitoLevelApply>(UserManitoLevelApply. class);
        return util.exportExcel(list, "userManitoLevelApply" );
    }

    /**
     * 获取大神等级申请详细信息
     */
    @ApiOperation(value = "获取大神等级申请详细信息",notes = "获取大神等级申请详细信息",response = AjaxResult.class)
    @PreAuthorize("@ss.hasPermi('system:userManitoLevelApply:query')" )
    @GetMapping(value = "/{id}" )
    public AjaxResult getInfo(@PathVariable("id" ) Long id) {
        return AjaxResult.success(iUserManitoLevelApplyService.getById(id));
    }

    /**
     * 新增大神等级申请
     */
    @ApiOperation(value = "新增大神等级申请",notes = "新增大神等级申请",response = AjaxResult.class)
    @PreAuthorize("@ss.hasPermi('system:userManitoLevelApply:add')" )
    @Log(title = "大神等级申请" , businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody UserManitoLevelApply userManitoLevelApply) {
        return toAjax(iUserManitoLevelApplyService.save(userManitoLevelApply) ? 1 : 0);
    }

    /**
     * 修改大神等级申请
     */
    @ApiOperation(value = "修改大神等级申请",notes = "修改大神等级申请",response = AjaxResult.class)
    @PreAuthorize("@ss.hasPermi('system:userManitoLevelApply:edit')" )
    @Log(title = "大神等级申请" , businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody UserManitoLevelApply userManitoLevelApply) {
        return toAjax(iUserManitoLevelApplyService.updateById(userManitoLevelApply) ? 1 : 0);
    }

    /**
     * 删除大神等级申请
     */
    @ApiOperation(value = "删除大神等级申请",notes = "删除大神等级申请",response = AjaxResult.class)
    @PreAuthorize("@ss.hasPermi('system:userManitoLevelApply:remove')" )
    @Log(title = "大神等级申请" , businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}" )
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(iUserManitoLevelApplyService.removeByIds(Arrays.asList(ids)) ? 1 : 0);
    }
}
